(function () {
  console.log("main");
  //  console.log(NavData)
  // 头部组件
  const Header = window.VueComponents.Header;
  // 底部组件
  const Footer = window.VueComponents.Footer;
  // 轮播图组件
  const BannerCom = window.VueComponents.BannerCom;
  // 卡片组件
  const CardCom = window.VueComponents.CardCom;
  const CardHead = window.VueComponents.CardHead;
  // 影视列表组件
  const VideoList = window.VueComponents.VideoList;
  // 排行榜列表组件
  const TopList = window.VueComponents.TopList;
  // 咨询列表组件
  const ConsultCom = window.VueComponents.ConsultCom;

  // 热榜列表
  const HotListData = window.APIDATA.HotListData;

  Vue.createApp({
    components: {
      BannerCom: BannerCom,
      CardCom,
      CardHead,
      VideoList,
      TopList,
      ConsultCom,
      HeaderCom: Header,
      FooterCom: Footer,
    },
    data: () => ({
      typeData: [],
      // 咨询列表
      information: {
        data1: [], //电影
        data2: [], //电视剧
        data3: [], //动漫
        data4: [], //综艺
      },
    }),
    created() {
      this.initData();
      this.initFormations();
    },
    methods: {
      initData() {
        // 初始化
        // 影视数据
        const TypeData = window.APIDATA.TypeData;
        // 标签数据
        const TagData = window.APIDATA.TagData;
        // 热度排行数据
        const HotData = window.APIDATA.HotData;
        const arrList = [
          {
            id: 0,
            title: "电影",
            icon: "./assets/movie.png",
          },
          {
            id: 1,
            title: "电视剧",
            icon: "./assets/tv.png",
          },
          {
            id: 2,
            title: "动漫",
            icon: "./assets/zong.png",
          },
          {
            id: 3,
            title: "综艺",
            icon: "./assets/man.png",
          },
        ];
        const temp = [];
        arrList.forEach((_, i) => {
          let type = TypeData(_.id); //所有影视数据
          let tag = TagData(_.id); //所有标签数据
          let hot = HotData(_.id); //排行榜
          // // 随机所有 其实只有两个
          const randomindex = Math.floor(Math.random() * tag.length);

          const typeData = type[randomindex];
          const hotData = hot[randomindex];

          temp.push({
            id: _.id,
            title: _.title,
            hotTitle: _.title + "榜单",
            icon: _.icon,
            hotIcon: "./assets/hot.png",
            items: typeData.splice(0, 12).map((item, index) => ({
              id: item.season_id,
              title: item.title,
              pic: item.order,
              desc: item.subTitle,
              img: item.cover,
              href: `second.html?id=${item.season_id}&type=${_.id}&tag=${tag[randomindex].id}`,
            })),
            cons: typeData.splice(0, 20).map((item) => ({
              id: item.season_id,
              title: item.title,
              type: item.order,
              href: `second.html?id=${item.season_id}&type=${_.id}&tag=${tag[randomindex].id}`,
            })),
            hots: hotData.splice(0, 20).map((item) => ({
              id: item.season_id,
              title: item.title,
              muted: item.order,
              href: `second.html?id=${item.season_id}&type=${_.id}&tag=${tag[randomindex].id}&hot=1`,
            })),
          });
        });

        console.log(temp);
        this.typeData = temp;

        // this.useData.videoTop = HotListData(0)
        //   .splice(0, 20)
        //   .map((item) => {
        //     return {
        //       id: item.season_id,
        //       muted: item.icon_font.text,
        //       title: item.title,
        //     };
        //   });
        // this.useData.tvTop = HotListData(1)
        //   .splice(0, 20)
        //   .map((item) => {
        //     return {
        //       id: item.season_id,
        //       muted: item.icon_font.text,
        //       title: item.title,
        //     };
        //   });
      },

      // 初始化资讯列表
      initFormations() {
        const result = {};
        // 初始化 其他热榜列表
        new Array(4).fill(1).forEach((_, i) => {
          result["data" + (i + 1)] = HotListData(i)
            .splice(0, 20)
            .map((item) => {
              return {
                id: item.season_id,
                muted: item.icon_font.text,
                title: item.title,
              };
            });
        });

        this.information = result;
      },
    },
  }).mount("#app");
})();
